package lc66;

/**
 * @Author Stringzhua
 * @Date 2024/3/26 16:57
 * description:
 */
public class Test02 {
    public int[] plusOne(int[] digits) {
        int k = digits.length - 1;
        while (k >= 0) {
            if (digits[k] != 9) {
                digits[k]++;
                break;
            }
            digits[k--] = 0;
        }
        if (k > 0) {
            int[] ans = new int[digits.length + 1];
            ans[0] = 1;
            return ans;
        }
        return digits;
    }

    public static void main(String[] args) {
        int[] digits = {4, 3, 2, 1};
        Test01 test01 = new Test01();
        test01.plusOne(digits);
        for (int i = 0; i < digits.length; i++) {
            System.out.print(i + " ");
        }
    }
}
